package com.hfzy.ihk.web.userCenter.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.client.OAuth2RestOperations;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Created by YANFA on 2019/2/27.
 */
@RequestMapping("my")
@RestController
@Slf4j
public class ApiController {



//    @Autowired
//    OAuth2RestOperations restOperations;

    @Autowired
    OAuth2RestOperations restOperations;

    @RequestMapping("/api2/test")
    public String test(){
        //获取权限看看
        OAuth2Authentication authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();

        String personResourceUrl = "http://10.10.37.142:8888/userCenter/my/api1/test";
//    mav.addObject("person",
//            restOperations.getForObject(personResourceUrl, String.class));
        System.out.println("token:"+restOperations.getAccessToken());
        String rs = restOperations.getForObject(personResourceUrl,String.class);

        log.info("======》返回值为："+rs);
        return "成功";
    }

    @RequestMapping("/api1/test")
    public String test1(){
//
//        String personResourceUrl = "http://10.10.37.142:8880/linkcall/my/api1/hi";
////    mav.addObject("person",
////            restOperations.getForObject(personResourceUrl, String.class));
//        System.out.println("token:"+restOperations.getAccessToken());
//        String rs = restOperations.getForObject(personResourceUrl,String.class);
        return "成功";
    }
}
